/**
 * 
 * @author BJS aka Zephyr
 * @version 0.5
 * @date 2012-05-01
 * 
 * navigation.css 필요
 */

var Navigation = function(id , type) {
	if(!type) type = 'navigation1';
	
	this.ct = {
		nav : type + "_nav",
		a : type + "_a",
		hover : type + "_hover",
		active : type + "_active",
	};
	
	this.nav = $('<nav>');
	this.nav.attr('id' , id);
	this.nav.addClass(this.ct.nav);
};

Navigation.prototype = {
	addMenu : function(id ,  text , href ) {
		var _this = this;
		var _nav = this.nav;
		var _ct = this.ct;
		var a = $('<a>');
		a.attr('id' , id);
		a.text(text);
		a.addClass(this.ct.a);
		a.attr('href' , href);
		
		a.hover(function(){
			a.addClass(_ct.hover);
		} , function(){
			a.removeClass(_ct.hover);
		});
		
		a.click(function(){
			_this.activateMenu(a);
		});
		
		this.nav.append(a);
		
		return a;
	},
	appendAfter : function( selector ) {
		$(selector).after(this.nav);
	},
	activateMenu : function( targetElem ) {
		var _nav = this.nav;
		var _ct = this.ct;
		_nav.find('a').each(function(){
			if( this == targetElem.get(0) ) {
				$(this).addClass(_ct.active);
			}
			else {
				$(this).removeClass(_ct.active);
			}
		});
	}
};